﻿/*
 *
 * @author	ZERO
 * @version 1.0
 * 
 */
 
 import com.dinmax.flash.sof.*;
 import com.dinmax.requirement.Requirement;
 
 class com.dinmax.requirement.RequirementFactory implements SOFService {
	 
    private var service:String;	 
	private var requirement:Requirement;
	private var NEW_SERVICE_REQUIREMENT:String="AddUser";
	private var UPDATE_SERVICE_REQUIREMENT:String="ModifyUser";

	public static function newInstance():RequirementFactory {
		return new RequirementFactory();	
	}
	
	function RequirementFactory(){
		//trace("new RequirementFactory");
	}
	
	public function save(requirement:Requirement) {
		this.requirement=requirement;
		service=UPDATE_SERVICE_REQUIREMENT;
		//Si el ID es indefinido es un alta
		if (requirement.getId()==undefined) {
			service=NEW_SERVICE_REQUIREMENT;
		}
		var manager:SOFManager=SOFManager.newInstance();
		manager.execute(this);					
	}
	
	function error(error:SOFServiceError) {
		trace("RequirementFactory.as | error()");
	}
	
	function getName():String {
		return this.service;
	}
	
	function getParameters():SOFServiceData {
		var parameters=new SOFServiceData();
		parameters.addClass("Requirement", requirement);
		return parameters;
	}
	
	function result(data:SOFServiceData):Void {
		trace("RequirementFactory.as | result()");
	}
	
}